﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.LightSwitch.ApplicationInfrastructure.Utilities.Internal;

namespace ExtensionsMadeEasy.Navigation.DeepLinkHandlers
{
    public sealed class EntityDeepLinkHandler : DeepLinkHandler
    {

        private string entityName;
        private string dataSource ;
        private int id;

        protected override bool Navigate()
        {
            return this.navigationModel.NavigateTo(entityName, dataSource, id);
        }

        protected override bool CanNavigate()
        {
            QueryStringHelper.TryGetAndParseValue("Id", out id);
            if (!QueryStringHelper.TryGetValue("DataSource", out dataSource)) {
                dataSource = "ApplicationData";
            }
            QueryStringHelper.TryGetValue("NavigateToEntity", out entityName);
            return (!string.IsNullOrEmpty(entityName));
        }
    }
}